<?php

namespace App\Http\Controllers\Erp;

use App\CodeResponse;
use App\Enum;
use App\Repositories\Stock\StockTransferItemRepository;
use App\Services\Stock\StockTransferItemService;
use Illuminate\Http\Request;

class StockTransferItemController extends ErpController
{

    protected $stockTransferItemRepository;

    public function __construct(StockTransferItemRepository $stockTransferItemRepository)
    {
        $this->stockTransferItemRepository = $stockTransferItemRepository;

    }

    public function list($transferId, Request $request)
    {
        $input = $request->input();
        $where['transfer_Id'] = $transferId;
        $where['is_enable'] = Enum::IS_ENABLE_TRUE;

        if (empty($input['is_all'])) {
            $list = $this->stockTransferItemRepository->getList(['*'], $where);
            return $this->paginate($list);
        } else {
            $list = $this->stockTransferItemRepository->getAll($where);
            return $this->success($list);
        }

    }


    public function create($transferId, Request $request)
    {
        $input = $request->input();
        $flag = StockTransferItemService::getInstance()->createItem($transferId, $input);
        return $this->failOrSuccess($flag, CodeResponse::CREATED_FAIL, $flag);

    }

    public function update($id, Request $request)
    {
        $input = $request->input();
        $flag = StockTransferItemService::getInstance()->updateItem($id, $input);
        return $this->failOrSuccess($flag, CodeResponse::UPDATED_FAIL, $flag);

    }

    public function delete($id)
    {
        $flag = StockTransferItemService::getInstance()->deleteItem($id);
        return $this->failOrSuccess($flag, CodeResponse::UPDATED_FAIL);

    }


}